﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Daemon.Data.Substructure.Framework.Extension
{
	public static class ObjectExtension
	{
		public static T CloneObject<T>(this T oldObj)
		{
			BinaryFormatter formatter = new BinaryFormatter();
			MemoryStream stream = new MemoryStream();
			formatter.Serialize(stream, oldObj);
			stream.Position = 0;
			return (T)formatter?.Deserialize(stream);
		}
	}
}
